<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2024/5/15
  Time: 15:17
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8"
         isELIgnored="false" language="java" %>
<html>
<head>
    <title>登录页面</title>
<%--    <script src="http://code.jquery.com/jquery-3.3.1.min.js"></script>--%>
    <script src="js/jquery-3.1.1.js"></script>
    <script>
        function gogo() {
            //获取文本框值
            var username = $("#name").val().trim();
            var password = $("#password").val().trim();
            $.ajax({
                url:"${pageContext.request.contextPath}/user/textRequest",
                type:"POST",
                data:{"username":username,"password":password},
                success:function (data) {
                    alert(data)
                    if(data=="ok"){
                        //登录成功
                        window.location.href="http://www.baidu.com";
                    }else{
                        //登录失败，即用户或密码错误
                        $("#errorMsg") .css("color","red");
                        $("#errorMsg").html(data);
                    }
                }
            });

        }
    </script>
</head>
<body>
<form>
    <table>
        <tr>
            <td>用户名：</td>
            <td>
                <input id="name" type="text" name="name" clas="textSize">
            </td>
        </tr>
        <tr>
            <td>密码：</td>
            <td>
                <input id="password" type="password" name="password" clas="textSize">
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <input type="button" value="登录" onclick="gogo()">
                <input type="button" value="取消">
                <span id="errorMsg"></span>
            </td>
        </tr>
    </table>
    </form>

 </body>
</html>